package com.zyj;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class LuceneUtils {

    public static  Directory ramDirectory =  new RAMDirectory();  //内存目录,重启服务索引需要重新加载

    public static Directory getDirectory() throws IOException {
        Directory directory = FSDirectory.open(new File("d:/LuceneData")); //初始化lucene索引目录
        return directory;
    }


    public static Analyzer getAnalyzer() {
        return new StandardAnalyzer(Version.LUCENE_47);
        //使用ik分词器
      //  return new IKAnalyzer();
    }

    public static Long stringToTime(String dateStr) throws ParseException {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateStr).getTime();
    }


}
